package com.coinworld.utils;

import com.alibaba.druid.filter.config.ConfigTools;

/**
 * @description 阿里Druid连接密码加密解密
 * @author:
 * @create: 2019-08-22 18:01
 **/
public class RsaEncryptAndDecodeUtil {

    /**
     * 公钥(用于解密)
     */
    private static final String RSA_PUBLIC_KEY = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBALSs7508432YfyWVesTJKjKGvl6U50GDMSSnPYXm7KrlhgK5NgCFfNUZm/wATC2XhAbnv5X6v3XC2CDbIWVcVN0CAwEAAQ==";

    /**
     * 私钥加密(用于加密)
     */
    private static final String RSA_PRIVATE_KEY = "";


    public static void main(String[] args) {
        String miwen = encrypt("");
        System.out.println("密文=====>" + miwen);
        String mingwen = decrypt(miwen);
        System.out.println("名文=====>" + mingwen);
    }

    /**
     * 描述 私钥加密
     */
    public static String encrypt(String strMing) {
        try {
            return ConfigTools.encrypt(RSA_PRIVATE_KEY, strMing);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;

    }

    /**
     * 描述 公钥解密
     */
    public static String decrypt(String strMi) {
        try {
            return ConfigTools.decrypt(RSA_PUBLIC_KEY, strMi);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


}
